import request from '@/utils/request'

// 引入数据类型
import type { categoryResponseData,attrResponseData,attrModel } from './model/attr'

// 枚举地址
enum API{
    C1="/admin/product/getCategory1",//一级分类接口
    C2='/admin/product/getCategory2/',//二级分类接口
    C3='/admin/product/getCategory3/',//三级分类接口
    ATTRLIST='/admin/product/attrInfoList/',//商品基础属性接口\
    ADDORUPDATEATTR='/admin/product/saveAttrInfo',// 添加或修改平台属性的接口
    DELATEATTR='/admin/product/deleteAttr/',// 删除某一个平台属性的接口
    ADD='/admin/product/spuImageList/',
    UPDATE='/admin/product/spuSaleAttrList/'

}

// 定义一级分类接口
export const reqC1List = () =>request.get<any,categoryResponseData>(API.C1)
// 定义二级分类接口
export const reqC2List = (category1Id:number|string) =>request.get<any,categoryResponseData>(API.C2+category1Id)
// 定义三级分类接口
export const reqC3List = (category2Id:number|string) =>request.get<any,categoryResponseData>(API.C3+category2Id)
// 定义商品基础属性接口
export const reqAttrList = (category1Id:number|string,category2Id:number|string,category3Id:number|string)=>request.get<any,attrResponseData>(API.ATTRLIST+`${category1Id}/${category2Id}/${category3Id}`)
// 添加或修改平台属性的接口
export const reqAddOrUpdateAttr= (data:attrModel)=>request.post<any,any>(API.ADDORUPDATEATTR,data)
// 删除某一个平台属性的接口
export const reqDeleteAttr = (attrId:number|undefined)=>request.delete<any,any>(API.DELATEATTR+attrId)

// 添加或修改一个SPU
export const reqAddOrUpdateSpu = (data:any)=>{
     if(data.id){
        // 修改
     return   request.post(API.ADD,data)
     }else {
        return request.post(API.UPDATE,data)
     }
}